﻿using UnityEngine;
using UnityGameFramework.Runtime;

    [DisallowMultipleComponent]
    public sealed class SystemInfoComponent : GameFrameworkComponent
    {
        public sealed class DeviceInfo
        {
            public DeviceInfo()
            {
                DeviceUniqueId = SystemInfo.deviceUniqueIdentifier;
                DeviceName = SystemInfo.deviceName;
                DeviceModel = SystemInfo.deviceModel;
                Platform = Application.platform;
            }

            /// <summary>
            /// 获取设备唯一编号。
            /// </summary>
            public string DeviceUniqueId
            {
                get;
                private set;
            }

            /// <summary>
            /// 获取设备名称。
            /// </summary>
            public string DeviceName
            {
                get;
                private set;
            }

            /// <summary>
            /// 获取设备类型。
            /// </summary>
            public string DeviceModel
            {
                get;
                private set;
            }

            /// <summary>
            /// 获取平台。
            /// </summary>
            public RuntimePlatform Platform
            {
                get;
                private set;
            }

            /// <summary>
            /// 获取网络是否连通。
            /// </summary>
            public NetworkReachability InternetReachability
            {
                get;
                private set;
            }
        }

        public sealed class CpuInfo
        {
            public CpuInfo()
            {
                ProcessorType = SystemInfo.processorType;
                ProcessorCount = SystemInfo.processorCount;
                ProcessorFrequency = SystemInfo.processorFrequency;
            }

            /// <summary>
            /// 获取处理器类型。
            /// </summary>
            public string ProcessorType
            {
                get;
                private set;
            }

            /// <summary>
            /// 获取处理器数量。
            /// </summary>
            public int ProcessorCount
            {
                get;
                private set;
            }

            /// <summary>
            /// 获取处理器主频。
            /// </summary>
            public int ProcessorFrequency
            {
                get;
                private set;
            }
        }

        public sealed class MemoryInfo
        {
            public MemoryInfo()
            {
                SystemMemorySize = SystemInfo.systemMemorySize;
                GraphicsMemorySize = SystemInfo.graphicsMemorySize;
            }

            /// <summary>
            /// 获取内存。
            /// </summary>
            public int SystemMemorySize
            {
                get;
                private set;
            }

            /// <summary>
            /// 获取显存。
            /// </summary>
            public int GraphicsMemorySize
            {
                get;
                private set;
            }
        }
        public sealed class ScreenInfo
        {
            public ScreenInfo()
            {
                ScreenWidth = UnityEngine.Screen.width;
                ScreenHeight = UnityEngine.Screen.height;
                ScreenDpi = UnityEngine.Screen.dpi;
            }

            /// <summary>
            /// 获取屏幕宽度。
            /// </summary>
            public int ScreenWidth
            {
                get;
                private set;
            }

            /// <summary>
            /// 获取屏幕高度。
            /// </summary>
            public int ScreenHeight
            {
                get;
                private set;
            }

            /// <summary>
            /// 获取屏幕点密度。
            /// </summary>
            public float ScreenDpi
            {
                get;
                private set;
            }
        }

        public sealed class SoftwareInfo
        {
            public SoftwareInfo()
            {
                OperatingSystem = SystemInfo.operatingSystem;
                UnityVersion = Application.unityVersion;
            }

            /// <summary>
            /// 获取操作系统。
            /// </summary>
            public string OperatingSystem
            {
                get;
                private set;
            }

            /// <summary>
            /// 获取 Unity 版本。
            /// </summary>
            public string UnityVersion
            {
                get;
                private set;
            }
        }

        private DeviceInfo m_DeviceInfo = null;
        private CpuInfo m_CpuInfo = null;
        private MemoryInfo m_MemoryInfo = null;
        private ScreenInfo m_ScreenInfo = null;
        private SoftwareInfo m_SoftwareInfo = null;

        /// <summary>
        /// 获取设备信息。
        /// </summary>
        public DeviceInfo Device
        {
            get
            {
                return m_DeviceInfo;
            }
        }

        /// <summary>
        /// 获取 CPU 信息。
        /// </summary>
        public CpuInfo Cpu
        {
            get
            {
                return m_CpuInfo;
            }
        }

        /// <summary>
        /// 获取内存信息。
        /// </summary>
        public MemoryInfo Memory
        {
            get
            {
                return m_MemoryInfo;
            }
        }

        /// <summary>
        /// 获取屏幕信息。
        /// </summary>
        public ScreenInfo Screen
        {
            get
            {
                return m_ScreenInfo;
            }
        }

        /// <summary>
        /// 获取软件信息。
        /// </summary>
        public SoftwareInfo Software
        {
            get
            {
                return m_SoftwareInfo;
            }
        }

        private void Start()
        {
            m_DeviceInfo = new DeviceInfo();
            m_CpuInfo = new CpuInfo();
            m_MemoryInfo = new MemoryInfo();
            m_ScreenInfo = new ScreenInfo();
            m_SoftwareInfo = new SoftwareInfo();
        }
    }
